package com.dragon.common.spring.business.base.jpa.audit;

import com.dragon.common.base.utils.DbUtil;
import jakarta.persistence.PrePersist;

/**
 * @author Chris Chan
 * Create On 2025/7/29 下午9:47
 * Use for: 公共审计监听
 * Explain:
 */
public class CommonAuditListener {
    @PrePersist
    public void prePersist(Object entity) {
        if (entity instanceof AbstractCommonAuditEntity auditEntity) {
            auditEntity.setCode(DbUtil.buildCode());
        }
    }

//    @PreUpdate
//    public void preUpdate(Object entity) {
//        if (entity instanceof AbstractCommonAuditEntity auditEntity) {
//            auditEntity.setCode(auditEntity.getCode());
//        }
//    }
}
